Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query engine integration #2074

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joshua-spacetime
Copy link
Collaborator

@joshua-spacetime joshua-spacetime commented Dec 19, 2024

Description of Changes

This patch integrates the new query engine into the query code path. It does not integrate the new engine into incremental evaluation path.

What is implemented?

  1. Instantiating tuple-at-a-time iterators from a physical plan
  2. The addition of a new query crate which is the top level crate for invoking the query engine.
  3. Invoking the new engine for initial subscriptions and one off queries
  4. Benchmarks

What isn't implemented?

  1. Incremental evaluation
  2. Multi-column index scans

Multi-column index scans have not been added to the optimizer yet, but they will be once we remove the old engine. We have a benchmark that will fail if the old engine is removed without adding multi-column index scans.

The old engine will be removed once incremental evaluation has been updated to use the new engine.

API and ABI breaking changes

n/a

Expected complexity level and risk

4

The query engine is responsible for implementing the subscription logic, which is the only way to read data out of SpacetimeDB. As such, its correctness and performance is paramount.

Testing

Does the new engine preserve correctness? Does it also preserve performance?

We have already added tests to ensure we preserve semantics, with more being worked on currently. This patch updates the applicable benchmarks to ensure we maintain performance characteristics.

full-scan               time:   [10.988 ms 11.039 ms 11.098 ms]
                        change: [-24.628% -24.131% -23.622%] (p = 0.00 < 0.05)
                        Performance has improved.

full-join               time:   [92.660 µs 92.817 µs 92.976 µs]
                        change: [-34.859% -34.730% -34.595%] (p = 0.00 < 0.05)
                        Performance has improved.

@joshua-spacetime joshua-spacetime self-assigned this Dec 19, 2024
@joshua-spacetime joshua-spacetime force-pushed the joshua/query-engine-integration branch from 3acec8b to 3e4ae13 Compare December 19, 2024 20:32
@joshua-spacetime joshua-spacetime force-pushed the joshua/query-engine-integration branch from 3e4ae13 to eaa2861 Compare December 19, 2024 21:00
Comment on lines +36 to +39
pub type Index<K> = multimap::MultiMap<K, RowPointer>;
pub type IndexIter<'a, K> = multimap::MultiMapRangeIter<'a, K, RowPointer>;
pub type UniqueIndex<K> = uniquemap::UniqueMap<K, RowPointer>;
pub type UniqueIndexIter<'a, K> = uniquemap::UniqueMapRangeIter<'a, K, RowPointer>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not needed. At least for right now.

@joshua-spacetime joshua-spacetime force-pushed the joshua/query-engine-integration branch from 8a4e30b to bace373 Compare December 20, 2024 06:22
impl<T: StateView> SchemaView for SchemaViewer<'_, T> {
fn table_id(&self, name: &str) -> Option<TableId> {
let AuthCtx { owner, caller } = self.auth;
self.tx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.tx
// Get the schema from the in-memory state instead of fetching from the database for speed

@@ -836,16 +837,24 @@ impl ModuleHost {
}

#[tracing::instrument(skip_all)]
pub fn one_off_query(&self, caller_identity: Identity, query: String) -> Result<Vec<MemTable>, anyhow::Error> {
pub fn one_off_query<F: WebsocketFormat>(
&self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now dead code? Why still here?

@@ -618,7 +743,7 @@ pub struct IxJoin {
/// The expression for computing probe values.
/// Values are projected from the lhs,
/// and used to probe the index on the rhs.
pub lhs_probe_expr: ProjectField,
pub lhs_field: TupleField,
Copy link
Contributor

@mamcx mamcx Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the rhs_label turn into TupleField instead?

@@ -575,25 +711,14 @@ pub enum Sarg {
Range(ColId, Bound<AlgebraicValue>, Bound<AlgebraicValue>),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In

pub enum Sarg {
     Range(ColId, Bound<AlgebraicValue>, Bound<AlgebraicValue>),
Suggested change
Range(ColId, Bound<AlgebraicValue>, Bound<AlgebraicValue>),
Range(BinOp,ColId, Bound<AlgebraicValue>, Bound<AlgebraicValue>),

(for the plan printer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants